#!/usr/bin/perl
use strict;
use warnings;

use FindBin;
use lib "$FindBin::Bin/../lib";

use POE;
use Net::DAAP::Server;
use Net::Rendezvous::Publish::Backend::BonjourWin32;

#XXX consider using nFileIndexHigh and nFileIndexLow by GetFileInformationByHandle() 
my $itemid = 1;

local *Net::DAAP::Server::Track::dmap_itemid = sub {
    my $self = shift;
    if (@_) {
        # $_[0] is inode, which isn't effective in win32 system
        $self->{dmap_itemid} = $itemid++;
    }
    $self->{dmap_itemid};
};

use Getopt::Long;

my $path;
my $port = 6666;
my $name = "Net::DMAP::Server with Bonjour Win32";

GetOptions("--path=s", \$path, "--port=i", \$port, "--name=s", \$name);

$path ||= $ARGV[0] or die "Usage: daap-server --port PORT --name NAME mp3_dir";
my $server = Net::DAAP::Server->new(
    path => $path,
    port => $port,
    name => $name,
);
$poe_kernel->run;
